Use case: ICACHE polling invalidate with error interrupt enabled ¶
This use case shows how to run a polling invalidate operation while the ICACHE error interrupt is enabled, comparing HAL1 and HAL2.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Optional: register error callback */
(void)HAL_ICACHE_RegisterErrorCallback(USER_ICACHE_ErrorCallback);
/* Enable ICACHE and enable error interrupt */
HAL_ICACHE_Enable();
__HAL_ICACHE_ENABLE_IT(ICACHE_IT_ERROR);
/* Polling invalidate */
if (HAL_ICACHE_Invalidate() != HAL_OK)
{
Error_Handler();
}
/* In ICACHE_IRQHandler(): */
/* HAL_ICACHE_IRQHandler(); */
|
/* Optional: register error callback */
(void)HAL_ICACHE_RegisterErrorCallback(&hicache1, myICACHE_ErrorCallback);
/* Start ICACHE with error interrupt enabled */
if (HAL_ICACHE_Start(&hicache1, HAL_ICACHE_IT_ERROR) != HAL_OK)
{
Error_Handler();
}
/* Polling invalidate */
if (HAL_ICACHE_Invalidate(&hicache1) != HAL_OK)
{
Error_Handler();
}
/* In ICACHE_IRQHandler(): */
/* HAL_ICACHE_IRQHandler(&hicache1); */
|
Key changes ¶
HAL2 enables error interrupt as part of the
HAL_ICACHE_Start()configuration, instead of using__HAL_ICACHE_ENABLE_IT().HAL2 keeps the invalidate API but updates it to a handle-based signature.
HAL2 supports optional callback registration (
HAL_ICACHE_RegisterErrorCallback()) when enabled at compile time.
![@startuml
participant "User\nApplication" order 1
participant "ICACHE\nDriver" order 2
participant "ICACHE\nIRQHandler" order 3
skinparam sequenceMessageAlign center
group Option Register Error Callback
"User\nApplication" ->"ICACHE\nDriver": HAL_ICACHE_RegisterErrorCallback(USER_ICACHE_ErrorCallback)
"ICACHE\nDriver"-->"User\nApplication":HAL_OK
end
"User\nApplication"->"ICACHE\nDriver": HAL_ICACHE_Enable
"User\nApplication"->"ICACHE\nDriver": __HAL_ICACHE_ENABLE_IT
note right: ICACHE_IT_ERROR
"ICACHE\nDriver"-->"User\nApplication":HAL_OK
"User\nApplication" [#blue]->"ICACHE\nDriver": HAL_ICACHE_Invalidate
activate "ICACHE\nDriver" #blue
note over "ICACHE\nDriver":Check Busy flag : Flag = 0
"ICACHE\nIRQHandler" <[#orange]-:ICACHE Error interrupt
"ICACHE\nIRQHandler" -[#orange]> "ICACHE\nDriver" : HAL_ICACHE_IRQHandler
activate "ICACHE\nDriver" #orange
note over "ICACHE\nDriver":Flag Error Interrupt = 1
"ICACHE\nDriver"-[#orange]>"User\nApplication":USER_ICACHE_ErrorCallback(HAL_ICACHE_ERROR_WRITE_INTRUSION)
"User\nApplication" -[#orange]->"ICACHE\nDriver"
deactivate "ICACHE\nDriver"
"ICACHE\nDriver"-[#blue]->"User\nApplication":HAL_OK
deactivate "ICACHE\nDriver"
note over "User\nApplication":For other user application
@enduml](../../../../../_images/plantuml-f05e7c171830fc5e734f5d21005c6a8a818c1885.png)
![@startuml
participant "User\nApplication" as UA order 1
participant "ICACHE\nDriver" as ID order 2
participant "ICACHE_IRQHandler" as IRQ order 3
skinparam sequenceMessageAlign center
== ICACHE Initialization ==
group Option [USE_HAL_ICACHE_REGISTER_CALLBACKS]
UA -> ID : HAL_ICACHE_RegisterErrorCallback(myICACHE_ErrorCallback)
ID --> UA : return HAL_OK
end
UA -> ID : HAL_ICACHE_Start(HAL_ICACHE_IT_ERROR)
rnote over ID
Enable ERROR interrupt
endrnote
ID --> UA : return HAL_OK
|||
UA [#blue]->ID: HAL_ICACHE_Invalidate
activate ID #blue
note over ID : Check Busy flag : Flag = 0
IRQ <[#orange]- : ICACHE Error interrupt
IRQ -[#orange]> ID : HAL_ICACHE_IRQHandler
activate ID #orange
note over ID : Flag Error Interrupt = 1
alt USE_HAL_ICACHE_REGISTER_CALLBACKS
ID-[#orange]>UA:myICACHE_ErrorCallback
UA -[#orange]->ID
else USE OVERRIDDEN WEAK CALLBACKS
ID-[#orange]>UA:HAL_ICACHE_ErrorCallback
UA -[#orange]->ID
end
deactivate ID
ID-[#blue]-> UA : return HAL_OK
deactivate ID
|||
rnote over UA
The user can call HAL_ICACHE_Stop() to disable the error interrupt
and stop ICACHE or take another action.
endrnote
@enduml](../../../../../_images/plantuml-73cb83ad6e9f610ccc43684bf4053c779759af68.png)